<#include "/template/_ListPageWithTree.html" /> <#assign
left_title="栏目列表"> <@left>
<ul id="lefttree" class="easyui-tree"
	url="${root!}/framecms/categoryTree"></ul>
<script type="text/javascript">
			$(function(){
				$('#lefttree').tree({
					onClick:function(node){
						$('#dg').datagrid({
							url:'${root!}/framecms/categoryTable?code='+node.attributes.code
						});
					}
				});
			});
</script>
</@left>
<@center> 
	<@datatable toolbar="#tb" id="dg" model="${root!}/framecms/newsTable" fit="true"> 
		<@columns> 
			<@column name="ck" checkbox="true" /> 
			<@column name="code" title="栏目编号" width="100" sortable="true" /> 
			<@column name="name" title="栏目名称" width="150" formatter="editName" /> 
			<@column name="shortname" title="栏目简称" width="150" />
			<@column name="disable" title="是否启用" width="100" formatter="realCate" />
			<@column name="order" title="排序号" width="100" /> 
			<@column name="id" hidden="true" /> 
		</@columns> 
	</@datatable>
<div id="tb" style="height: auto">
	<div style="margin-bottom: 5px; border-bottom: 1px solid #ddd;">
		<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"
			onclick="addCate();">新增栏目</a> <a href="#" class="easyui-linkbutton"
			onclick="deleteCate()"
			data-options="plain:true,iconCls:'icon-cancel'">删除选中</a>
	</div>
</div>

<div id="dlg" class="easyui-dialog"
	style="width: 400px; height: 280px; padding: 10px 20px" closed="true"
	buttons="#dlg-buttons">
	<form id="fm" method="post" novalidate>
		<div class="fitem">
			<label>上级栏目:</label> <select id="cc" class="easyui-combotree"  data-options="url:'${root!}/framecms/categoryTree'"  name="parentId" style="width:156px;"></select>
			<a id="clean-parent" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-back'"></a>
		</div>
		<div class="fitem">
			<label>栏目名称:</label> <input name="name"
				class="easyui-validatebox" required="true">
		</div>
		<div class="fitem">
			<label>栏目简称:</label> <input name="shortname"
				class="easyui-validatebox" required="true">
		</div>
		<div class="fitem">
			<label>自定义编号:</label> <input name="customcode">
		</div>
		<div class="fitem">
			<label>是否启用:</label> <@intCheckbox id="cb"  name="disable" />
		</div>
		<div class="fitem">
			<label>排序号:</label> <input type="number" name="order" value="0" data-options="required:false" >
		</div>
	</form>
</div>
<div id="dlg-buttons">
	<a href="javascript:void(0)" class="easyui-linkbutton"
		iconCls="icon-ok" onclick="saveCate()">Save</a> <a
		href="javascript:void(0)" class="easyui-linkbutton"
		iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">Cancel</a>
</div>

<script type="text/javascript">

var url="";

function addCate(){
	var node = $('#lefttree').tree('getSelected');
	var parent=node ? node.id:"";
	$('#dlg').dialog('open').dialog('setTitle','新增栏目');
	$('#cc').combotree('setValue', parent);
	url="${root!}/framecms/saveCate";
}

function saveCate(){
	$('#fm').form('submit',{
		url:url,
		onSubmit:function(){
			return $(this).form("validate");
		},
		success:function(result){
			Alert.info(result,"系统消息");
			$('#dlg').dialog('close');
            $('#dg').datagrid('reload');
            $('#lefttree').tree('reload');
		}
	});	
}

function editName(val,row){
	var index = $('#dg').datagrid('getRowIndex',row);
	return '<a href="#" onclick="editCate(\''+index+'\')">'+val+'</a>';
}

function editCate(index){
	$('#dg').datagrid('selectRow',index);
	var row = $('#dg').datagrid('getSelected');
    if (row){
        $('#dlg').dialog('open').dialog('setTitle','Edit User');
        $('#fm').form('load',row);
        $('#cc').combotree('setValue', row.parentid);
        url="${root!}/framecms/updateCate?id="+row.id;
    }
}

function realCate(val,row){
	var check = val?"checked":"";
	return '<input type="checkbox" '+check+' >';
}


function deleteCate(){
	var rows = $('#dg').datagrid("getChecked");
	if(rows.length==0){
		Alert.info("未选择数据");
	}else{
		var ids=StringUtil.array2Str(rows,"id",";");
		$.ajax({
			url:"${root!}/framecms/delete?ids="+ids,
			type:"GET",
			success:function(msg){
				Alert.info(msg,"系统消息","refresh");
			}
		});
	}
}

$(function(){
	$('#clean-parent').bind('click',function(){
		$('#cc').combotree('setValue', '');
	});
});

</script>
</@center>
